package com.monitor.controller;


import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.mapper.EntityWrapper;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.monitor.entity.ErpManagement;
import com.monitor.entity.ErpSystemMessage;
import com.monitor.service.ErpManagementService;
import com.monitor.service.ErpSystemMessageService;
import com.monitor.util.Result;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

/**
 * <p>
 * 消息表 前端控制器
 * </p>
 *
 * @author 
 * @since 2018-11-19
 */
@RestController
@RequestMapping("/erpSystemMessage")
public class ErpSystemMessageController {
	@Autowired
	private ErpSystemMessageService erpSystemMessageService;
	
	 @RequestMapping("/getList")
	 @ApiOperation("用户消息列表")
	 @ApiImplicitParams({
		 @ApiImplicitParam(name = "custId", value = "客户ID", required = false, dataType = "int", paramType = "query")
	 })
	 public Result<List<ErpSystemMessage>> getList(int custId){
		 return erpSystemMessageService.getList(custId);
	 }


	@RequestMapping("/updatebyid")
	@ApiOperation("更改状态 已读 ")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "id", value = "信息id", required = false, dataType = "int", paramType = "query")
	})
	public String updatebyid(int id){
		try {
			ErpSystemMessage obj= erpSystemMessageService.selectById(id);
			obj.setSendFlag("已读");
			boolean i= erpSystemMessageService.updateById(obj);
			if(i){
                return JSON.toJSONString("ok");
            }else{
                return JSON.toJSONString("no");
            }
		} catch (Exception e) {
			return JSON.toJSONString("err");
		}

	}

	@RequestMapping("/addMessage")
	 @ApiOperation("发送消息")
	 @ApiImplicitParams({
		@ApiImplicitParam(name = "sendUserId", value = "发送方user id", required = false, dataType = "int", paramType = "query"),
		@ApiImplicitParam(name = "sendUserName", value = "发送方人名", required = false, dataType = "String", paramType = "query"),
		@ApiImplicitParam(name = "receiveUserId", value = "接收方user id", required = false, dataType = "int", paramType = "query"),
		@ApiImplicitParam(name = "sendContent", value = "消息内容", required = false, dataType = "String", paramType = "query"),
		@ApiImplicitParam(name = "messageType", value = "消息类型", required = false, dataType = "String", paramType = "query"),
		@ApiImplicitParam(name = "priority", value = "优先级", required = false, dataType = "String", paramType = "query"),
		@ApiImplicitParam(name = "companys", value = "所在单位", required = false, dataType = "String", paramType = "query")
	 })
	 public Result<Integer> addMessage(ErpSystemMessage message){
		 return erpSystemMessageService.addMessage(message);
	 }
}

